package com.example.controller;

import com.alibaba.fastjson.JSONArray;
import com.example.pojo.InterviewArrange;
import com.example.service.IInterviewArrangeService;
import com.example.vo.ResultVo;
import com.example.vo.per.IASendEmailParams;
import com.example.vo.respvo.IHandleSendOffice;
import com.example.vo.respvo.InterviewHandle;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 面试安排表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-15
 */
@RestController
@RequestMapping("/per/interview-arrange")
@Api(tags = "面试安排管理",value = "")
@CrossOrigin(allowCredentials = "true")
public class InterviewArrangeController {

    @Autowired
    private IInterviewArrangeService interviewArrangeService;

    @ApiOperation(value = "面试处理记录")
    @GetMapping("/handle")
    public PageInfo<InterviewHandle> getInterviewHandlePageInfo(
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "10")Integer pageSize
    ){
        return interviewArrangeService.getInterviewHandlePageInfo(pageNum,pageSize);
    }

    @PostMapping("")
    @ApiOperation(value = "添加面试安排")
    public ResultVo addInterviewArrange(@RequestBody InterviewArrange interviewArrange){
        System.err.println("in -> " + interviewArrange);
        interviewArrange.setStatus(1);
        if(interviewArrangeService.save(interviewArrange)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @PostMapping("/send-e")
    @ApiOperation("根据账号发送邮件并修改状态")
    public ResultVo uptSendEmail(@RequestBody JSONArray jsonArray){
        List<IASendEmailParams> iaSendEmailParams = jsonArray.toJavaList(IASendEmailParams.class);
        interviewArrangeService.sendEmailByE(iaSendEmailParams);
        return ResultVo.ok();
    }


    @GetMapping("/page-info")
    @ApiOperation(value = "获取面试安排表格")
    public PageInfo<InterviewArrange> getInterviewArrangePageInfo(
            Integer hr,
            @RequestParam(defaultValue = "0") Integer interCycle,
            String position,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
            ){
        return interviewArrangeService.getInterviewArrangePageInfo(hr,position,interCycle,pageNum,pageSize);
    }

    @GetMapping("/hr-options")
    @ApiOperation(value = "获取面试人员选项")
    public ResultVo getHrList(){
        return interviewArrangeService.getHrList();
    }

    @GetMapping("/position-options")
    @ApiOperation(value = "获取面试岗位选项")
    public ResultVo getPositionOptions(){
        return interviewArrangeService.getPositionOptions();
    }

    @PutMapping("")
    @ApiOperation(value = "修改面试安排记录")
    public ResultVo updateInterviewArrange(@RequestBody InterviewArrange interviewArrange){
        System.err.println("修改面试安排记录 -> " + interviewArrange);
        if(interviewArrangeService.updateById(interviewArrange)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @PostMapping("/issue-contract")
    @ApiOperation("发送office 并 修改岗位需求数量")
    public ResultVo sendAndUptById(@RequestBody IHandleSendOffice ihso){
        System.err.println(ihso + " - ---- > ");
        Boolean byIam = interviewArrangeService.sendEmailByIam(ihso);
        if (byIam){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @DeleteMapping("")
    @ApiOperation("删除面试记录及简历")
    public ResultVo delResume(@RequestParam("rcid") Integer rid
            ,@RequestParam("iaid")Integer iaid){
        Boolean aBoolean = interviewArrangeService.delinterviewRecordAndResume(rid, iaid);
        if (aBoolean){
            return ResultVo.ok();
        }
        return ResultVo.error("简历分类编号或面试记录表编号错误");
    }
}
